package com.nidu.demo.oauth2.executor.query;

import com.alibaba.cola.dto.PageResponse;
import com.nidu.demo.oauth2.convertor.OAuth2CodeCriteriaConvertor;
import com.nidu.demo.oauth2.dto.OAuth2CodePageQry;
import com.nidu.demo.oauth2.convertor.OAuth2CodeConvertor;
import com.nidu.demo.oauth2.dto.OAuth2CodeCO;
import com.nidu.demo.oauth2.gateway.OAuth2CodeGateway;
import com.nidu.demo.oauth2.model.OAuth2Code;
import com.nidu.demo.oauth2.model.OAuth2CodeCriteria;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Component;

import java.util.List;

@Component
@RequiredArgsConstructor
public class OAuth2CodePageQryExe {

    private final OAuth2CodeGateway gateway;

    private final OAuth2CodeConvertor convertor;

    private final OAuth2CodeCriteriaConvertor criteriaConvertor;

    public PageResponse<OAuth2CodeCO> execute(OAuth2CodePageQry qry) {
        OAuth2CodeCriteria criteria = criteriaConvertor.toDataObject(qry);
        PageResponse<OAuth2Code> page = gateway.pageByCondition(criteria);
        List<OAuth2CodeCO> codeCOS = convertor.toClientObjects(page.getData());
        return PageResponse.of(codeCOS, page.getTotalCount(), page.getPageSize(), page.getPageIndex());
    }
    
}
